using UnityEngine;

public class Pool : MonoBehaviour
{
	public GameObject[] groupList;

	public GameObject[] PrefabList;

	public int[] prefabAmountList;

	[Header("장비이미지")]
	public GameObject euipImage;

	[Header("떨어진장비컨테이너")]
	public Transform TF_EquipContainerOnFloor;

	[Header("장비리스트")]
	public GameObject[] WeaponPrefabList;

	public GameObject[] ArmorPrefabList;

	public WeaponAbility[] SCRT_WeaponAbilityList;

	private int countOfKind = 50;

	private int countOfPrefab = 100;

	public GameObject[,] goList { get; set; }

	private void Start()
	{
		goList = new GameObject[countOfKind, countOfPrefab];
		AllObjectsInfo.Init();
		CreatePrefabs();
		CreateSCRTWeaponAbilityList();
	}

	private void CreatePrefabs()
	{
		for (int i = 0; i < PrefabList.Length; i++)
		{
			for (int j = 0; j < prefabAmountList[i]; j++)
			{
				goList[i, j] = Object.Instantiate(PrefabList[i]);
				goList[i, j].transform.SetParent(groupList[i].transform, false);
				SetScript(i, j);
				goList[i, j].SetActive(false);
			}
		}
	}

	private void SetScript(int kind, int arrayNumber)
	{
		switch (kind)
		{
		case 3:
			AllObjectsInfo.SCRT_GrenadeList[arrayNumber] = goList[kind, arrayNumber].GetComponent<Grenade>();
			break;
		case 7:
			AllObjectsInfo.SCRT_DamageTextList[arrayNumber] = goList[kind, arrayNumber].GetComponent<DamageText>();
			break;
		case 8:
			AllObjectsInfo.SCRT_EnergeBallList[arrayNumber] = goList[kind, arrayNumber].GetComponent<EnergeBall>();
			break;
		case 12:
			AllObjectsInfo.SCRT_Arrow1List[arrayNumber] = goList[kind, arrayNumber].GetComponent<Arrow1>();
			break;
		case 20:
			AllObjectsInfo.SCRT_Lightning1List[arrayNumber] = goList[kind, arrayNumber].GetComponent<Lightning1>();
			break;
		case 23:
			AllObjectsInfo.SCRT_FreezingTrapList[arrayNumber] = goList[kind, arrayNumber].GetComponentInChildren<FreezingTrap>();
			break;
		case 24:
			AllObjectsInfo.SCRT_HUDtargetingCircleList[arrayNumber] = goList[kind, arrayNumber].GetComponentInChildren<HUD_TargetingCircle>();
			break;
		case 25:
			AllObjectsInfo.SCRT_ShockStunRingList[arrayNumber] = goList[kind, arrayNumber].GetComponent<ShockStunRing>();
			break;
		case 26:
			AllObjectsInfo.SCRT_HUDOutOfScreenTheTarget[arrayNumber] = goList[kind, arrayNumber].GetComponentInChildren<HUD_OutOfScreenTheTarget>();
			break;
		case 28:
			AllObjectsInfo.SCRT_HommingMagic1[arrayNumber] = goList[kind, arrayNumber].GetComponentInChildren<HommingMagic1>();
			break;
		}
	}

	private void CreateSCRTWeaponAbilityList()
	{
		SCRT_WeaponAbilityList = new WeaponAbility[WeaponPrefabList.Length];
		for (int i = 0; i < WeaponPrefabList.Length; i++)
		{
			SCRT_WeaponAbilityList[i] = WeaponPrefabList[i].GetComponent<WeaponAbility>();
		}
	}

	public void DeActiveAllObject()
	{
		for (int i = 0; i < countOfKind; i++)
		{
			for (int j = 0; j < countOfPrefab; j++)
			{
				if ((bool)goList[i, j])
				{
					goList[i, j].SetActive(false);
				}
			}
		}
		int childCount = TF_EquipContainerOnFloor.childCount;
		for (int k = 0; k < childCount; k++)
		{
			Object.Destroy(TF_EquipContainerOnFloor.GetChild(0).gameObject);
		}
	}
}
